package br.livro.android.cap5;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class ExemploRetornoIntent extends Activity implements OnClickListener{

	private static final int SELECIONAR_CONTATO = 1;
	private static final String CATEGORIA = "livro";
	
	@Override
	public void onCreate(Bundle icicle){
		super.onCreate(icicle);
		setContentView(R.layout.tela_visualizar_contatos);
		Button button = (Button) findViewById(R.id.botaoOk);
		button.setOnClickListener(this);
	}
	
	@Override
	public void onClick(View v) {
		Uri uri = Uri.parse("content://com.android.contacts/contacts/");
		Intent it = new Intent(Intent.ACTION_PICK,uri);
		startActivityForResult(it, SELECIONAR_CONTATO);
	}
	
	@Override
	protected void onActivityResult(int codigo, int resultado, Intent it){
		if(it == null){
			Toast.makeText(this, "Nenhum Contato", Toast.LENGTH_SHORT).show();
			return;
		}
		Uri uri = it.getData();
		//Toast.makeText(this, "Contato: "+uri, Toast.LENGTH_SHORT).show();
		startActivity(new Intent(Intent.ACTION_VIEW,uri));
	}

}
